package cn.tedu.musicsys.service.impl;

import cn.tedu.musicsys.domain.PlayRecord;
import cn.tedu.musicsys.domain.User;
import cn.tedu.musicsys.mapper.RecordPlayMapper;
import cn.tedu.musicsys.mapper.UserMapper;
import cn.tedu.musicsys.service.RecordPlayService;
import cn.tedu.musicsys.utils.Request;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


@Service("recordPlayService")
public class RecordPlayServiceImpl implements RecordPlayService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	private RecordPlayMapper recordPlayMapper;

	@Override
	public void recordPlay(HttpServletRequest request, int songId) {
		User user=userMapper.selectByUser(Request.getUserFromHttpServletRequest(request));
		recordPlayMapper.insert(new PlayRecord(user.getUserId(),songId));
		
	}

	@Override
	public List<PlayRecord> getAllRecords() {
		return recordPlayMapper.selectAll();
	}
	

}
